package com.example.lotteryticketdev.controller;



import com.example.lotteryticketdev.entity.User;
import com.example.lotteryticketdev.result.Result;
import com.example.lotteryticketdev.service.UserService;
import com.example.lotteryticketdev.tool.JwtHelper;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;


/**
 * (User)表控制层
 *
 * @author makejava
 * @since 2023-09-26 22:28:32
 */
@CrossOrigin
@RestController
@RequestMapping("/api/user")
public class UserController  {
    /**
     * 服务对象
     */
    @Resource
    private UserService userService;

    @GetMapping("/info")
    public Result info(@RequestParam String token){
        String name = JwtHelper.getUserName(token);
        String avatar = name;
        Map<String, Object> resultMap = new HashMap<>();
        resultMap.put("name",name);
        resultMap.put("avatar",avatar);
        return Result.ok(resultMap) ;
    }

    @PostMapping("/login")
    public Result login(@RequestBody User user){
        Result result = userService.login(user);
        return result ;
    }
}

